#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

bool lemonadeChange(vector<int>& bills) {
    unordered_map<int, int> hash;

    for (auto& money : bills)
    {
        hash[money]++;
        if (money == 10)
        {
            if (hash[5] != 0)
                hash[5]--;
            else
                return false;
        }
        else if (money == 20)
        {
            if (hash[10] != 0 && hash[5] != 0)
            {
                hash[10]--;
                hash[5]--;
            }
            else
            {
                if (hash[5] >= 3)
                    hash[5] -= 3;
                else
                    return false;
            }
        }
    }

    return true;
}

int main()
{
    vector<int> biils = { 5,5,10,10,20  };
    lemonadeChange(biils);
	return 0;
}